/*
* jlb
*/
package com.jlb.user.ctrl;

import com.alibaba.fastjson.JSON;
import com.jlb.core.entity.BeanRet;
import com.jlb.core.entity.Page;
import com.jlb.core.tools.redis.RedisUtils;
import com.jlb.user.entity.User;
import com.jlb.user.entity.UserJlb;
import com.jlb.user.service.UserJlbSV;
import com.jlb.user.service.UserSV;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * 金兰宝 控制器
 *
 * @author jlb
 */
@RestController
@RequestMapping("/userJlb")
@Slf4j
@Api(value = "金兰宝控制器", description = "金兰宝控制器")
public class UserJlbCtrl {

    @Resource
    protected RedisUtils redisUtils;

    @Resource
    private UserJlbSV userJlbSV;

    @Resource
    private UserSV userSV;

    /**
     * 查询UserJlb一个详情信息
     *
     * @param id
     * @param code 编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询UserJlb一个详情信息", notes = "查询UserJlb一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", dataType = "java.lang.String", paramType = "query")
    })
    @GetMapping(value = "/load")
    @ResponseBody
    public BeanRet load(java.lang.Long id, java.lang.String code) {
        if (id == null) {
            return null;
        }
        if (code == null) {
            return null;
        }
        UserJlb userJlb = userJlbSV.load(id, code);
        log.info(JSON.toJSONString(userJlb));
        return BeanRet.create(true, "查询成功", userJlb);
    }


    /**
     * 根据条件id查询UserJlb一个详情信息
     *
     * @param id
     * @return BeanRet
     */
    @ApiOperation(value = "查询UserJlb一个详情信息", notes = "查询UserJlb一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "path")
    })
    @GetMapping(value = "/load/id/{id}")
    @ResponseBody
    public BeanRet loadById(@PathVariable java.lang.Long id) {
        if (id == null) {
            return null;
        }
        UserJlb userJlb = userJlbSV.loadById(id);
        log.info(JSON.toJSONString(userJlb));
        return BeanRet.create(true, "查询成功", userJlb);
    }

    /**
     * 根据条件code查询UserJlb一个详情信息
     *
     * @param code 编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询UserJlb一个详情信息", notes = "查询UserJlb一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "编码", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/code/{code}")
    @ResponseBody
    public BeanRet loadByCode(@PathVariable java.lang.String code) {
        if (code == null) {
            return null;
        }
        UserJlb userJlb = userJlbSV.loadByCode(code);
        log.info(JSON.toJSONString(userJlb));
        return BeanRet.create(true, "查询成功", userJlb);
    }


    /**
     * 查询UserJlb信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询UserJlb信息集合", notes = "查询UserJlb信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "account", value = "用户账户", required = true, paramType = "query"),
            @ApiImplicitParam(name = "state", value = "状态:激活 Active，冻结 Frozen", required = true, paramType = "query"),
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
    })
    @GetMapping(value = "/list")
    @ResponseBody
    public BeanRet list(String account, @ApiIgnore UserJlb userJlb, Integer curPage, Integer pageSize) {

        Page<UserJlb> page = new Page<UserJlb>(pageSize, curPage);
        if (StringUtils.isNotBlank(account)) {
            User user = userSV.loadByAccount(account);
            if (user == null) {
                return BeanRet.create(true, "查询成功", page);
            }
            userJlb.setUserCode(user.getCode());
        }
        List<UserJlb> userJlbs = userJlbSV.list(userJlb, page.genRowStart(), page.getPageSize());
        page.setVoList(userJlbs);
        int total = userJlbSV.count(userJlb);
        page.setTotalRow(total);

        return BeanRet.create(true, "查询成功", page);

    }


    /**
     * 查询UserJlb信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询UserJlb信息集合", notes = "查询UserJlb信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query")
    })
    @GetMapping(value = "/list/by")
    @ResponseBody
    public BeanRet listByPk(java.lang.Long id, java.lang.String code, Integer curPage, Integer pageSize) {
        Page<UserJlb> page = new Page<UserJlb>(pageSize, curPage);
        List<UserJlb> userJlbs = userJlbSV.list(id, code, page.genRowStart(), page.getPageSize());
        page.setVoList(userJlbs);
        int total = userJlbSV.count(id, code);
        page.setTotalRow(total);

        return BeanRet.create(true, "查询成功", page);
    }

    /**
     * 统计UserJlb信息数量根据主键
     *
     * @return 总条数
     */
    @ApiOperation(value = " 统计UserJlb信息数量根据主键", notes = " 统计UserJlb信息数量根据主键")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query")
    })
    @GetMapping(value = "/count/by")
    @ResponseBody
    public Integer count(java.lang.Long id, java.lang.String code) {
        return userJlbSV.count(id, code);
    }

    /**
     * 统计UserJlb信息数量
     *
     * @return 总条数
     */
    @ApiOperation(value = "统计UserJlb信息数量", notes = "统计UserJlb信息数量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
            @ApiImplicitParam(name = "userCode", value = "用户编码", paramType = "query"),
            @ApiImplicitParam(name = "jlb", value = "金兰宝总数量", paramType = "query"),
            @ApiImplicitParam(name = "release", value = "已释放数量", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "状态:激活 Active，冻结 Frozen", paramType = "query")
    })
    @GetMapping(value = "/count")
    @ResponseBody
    public Integer count(@ApiIgnore UserJlb userJlb) {
        if (userJlb == null) {
            return userJlbSV.count(new HashMap());
        } else {
            return userJlbSV.count(userJlb);
        }
    }


    /**
     * 创建UserJlb
     *
     * @return BeanRet
     */
    @ApiOperation(value = "创建UserJlb", notes = "创建UserJlb")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userCode", value = "用户编码", paramType = "query"),
            @ApiImplicitParam(name = "jlb", value = "金兰宝总数量", paramType = "query"),
            @ApiImplicitParam(name = "release", value = "已释放数量", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "状态:激活 Active，冻结 Frozen", paramType = "query")
    })
    @PostMapping("/build")
    @ResponseBody
    public BeanRet build(@ApiIgnore UserJlb userJlb) {
        userJlbSV.save(userJlb);
        return BeanRet.create(true, "创建成功", userJlb);
    }


    /**
     * 金兰宝转账
     *
     * @return BeanRet
     */
   /* @ApiOperation(value = "修改UserJlb", notes = "修改UserJlb")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "outAccount", value = "转出金兰宝用户账户", paramType = "query"),
            @ApiImplicitParam(name = "inAccount", value = "转入金兰宝用户账户", paramType = "query"),
            @ApiImplicitParam(name = "jlb", value = "金兰宝数量", paramType = "query")
    })
    @PutMapping("/transfer")
    @ResponseBody
    public BeanRet transfer(String outAccount, String inAccount, Integer jlb) {
        userJlbSV.transfer(outAccount, inAccount, jlb);
        return BeanRet.create(true, "修改成功");
    }
*/

    /**
     * 修改UserJlb
     *
     * @return BeanRet
     */
    @ApiOperation(value = "修改UserJlb", notes = "修改UserJlb")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
            @ApiImplicitParam(name = "userCode", value = "用户编码", paramType = "query"),
            @ApiImplicitParam(name = "jlb", value = "金兰宝总数量", paramType = "query"),
            @ApiImplicitParam(name = "release", value = "已释放数量", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "状态:激活 Active，冻结 Frozen", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public BeanRet modify(@ApiIgnore UserJlb userJlb) {
        userJlbSV.modify(userJlb);
        return BeanRet.create(true, "修改成功", userJlb);
    }

    /**
     * 删除UserJlb
     *
     * @return BeanRet
     */
    @ApiOperation(value = "删除UserJlb", notes = "删除UserJlb")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query")
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public BeanRet delete(java.lang.Long id, java.lang.String code) {
        userJlbSV.delete(id, code);
        return BeanRet.create(true, "删除UserJlb成功");
    }

}
